/*
  Copyright (C) 2011, Kyungjoo Kim
  
  This file is part of UHM (Unassembled HyperMatrix) sparse direct solver.
  
  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Also add information on how to contact you by electronic and paper mail.
  
  
  Kyungjoo Kim
  iamkyungjoo@gmail.com
*/
#ifndef UHM_INTERF_MUMPS_HXX
#define UHM_INTERF_MUMPS_HXX

namespace uhm {

  namespace interf {
    typedef class  Mumps_*         Mumps;

    // ----------------------------------------------------------------
    // ** MUMPS
    class Mumps_ {
    private:
    protected:
      int datatype, show_n_rhs;

      DMUMPS_STRUC_C dmumps;
      ZMUMPS_STRUC_C zmumps;
    
      // matrix CSR format
      int n_dof, n_rhs, n_nz;
      std::vector<int> ia, ja;
      std::vector<double> a, b, x;

      void _init(int datatype) {
        assert(datatype == UHM_REAL ||
               datatype == UHM_COMPLEX);
        this->datatype = datatype;
        this->show_n_rhs = 0;
      }

    public:
      Mumps_() { _init(UHM_REAL); }
      Mumps_(int datatype) { _init(datatype); }
      virtual ~Mumps_() { }

      bool   export_matrix(Mesh m);

      void   disp();
      void   disp( FILE *stream );

      bool   is_complex();

      void   set_show_n_rhs(int show_n_rhs);

      void   set_par    (int par);
      void   set_sym    (int sym);
      void   set_comm   (int comm);
      void   set_job    (int job);
    
      void   set_icntl  (int idx, int val);
      void   set_cntl   (int idx, double val);
      void   set_perm_in(int *perm_in);

      void   set_sparse_matrix(Sparse sp, int is_sym);

      int    get_par();
      int    get_sym();
      int    get_comm();
      int    get_job();

      int    get_icntl  (int idx);
      double get_cntl   (int idx);

      int    get_info   (int idx);
      int    get_infog  (int idx);
      double get_rinfo  (int idx);
      double get_rinfog (int idx);
    
      int    get_n_dof();
      int    get_n_rhs();
      int    get_n_nonzero();

      bool   validate_sparse_matrix();
      int    run();

      bool   init();
      bool   analyze();
      bool   decompose();
      bool   solve();
      bool   finalize();
    };

    // ----------------------------------------------------------------
  }
}

#endif
